package com.smc.hookdemo;

import com.smc.test.TestActivity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;


public class MainActivity extends Activity {

	private final int MSG_DELAY_TEST = 10000;
	private Handler handler;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
        
        handler.sendEmptyMessageDelayed(MSG_DELAY_TEST, 1000);
    }
    
    
    
    private void init()
    {
    	initHook();
    	initHandler();
    }
    
    private void initHandler()
    {
    	handler = new Handler(){
    		@Override
    		public void handleMessage(Message msg)
    		{
    			int what = msg.what;
    			switch(what){
	    			case MSG_DELAY_TEST:
	    				startTestActivity();
	    				break;
    			}
    		}
    	};
    }
    
    private void initHook(){
    	try {
			HookUtils.hookAMS();
			HookUtils.hookHandler();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    }
    
    private void startTestActivity(){
    	Intent localIntent = new Intent();
    	localIntent.setClassName("com.smc.hookdemo", "com.smc.test.TestActivity");
    	try{
    		startActivity(localIntent);
    	}catch(Exception e){
    		e.printStackTrace();
    	}
    }
    
}
